class Solution
{
public:
    int minSideJumps(vector<int> &obstacles)
    {
        int n = obstacles.size();
        vector<vector<int>> dp(n, vector<int>(3, 0));
        int minJump = 0;
        dp[0] = {1, 0, 1};
        for (int i = 1; i < n; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                if (j == obstacles[i] - 1)
                {
                    dp[i][j] = INT_MAX;
                }
                else
                {
                    dp[i][j] = dp[i - 1][j];
                }
            }
            minJump = min(dp[i][0], min(dp[i][1], dp[i][2]));
            for (int j = 0; j < 3; ++j)
            {
                if (j != obstacles[i] - 1)
                {
                    dp[i][j] = min(dp[i][j], minJump + 1);
                }
            }
        }
        return min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2]));
    }
};